/*
 * @Author: dujianmin@qq:20130527
 * @Date: 2024-07-19 23:21:46
 * @Last Modified by: dujianmin
 * @Last Modified time: 2024-07-20 00:34:10
 */

#include <stdio.h>
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"


#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"

#include "esp_log.h"
#include <cJSON.h>

#include "du_websocket_client.h"
#include "du_bsp_spiffs.h"
#include "du_bsp_wifi_sta.h"

#include "du_http_client.h"

static const char *TAG = "robot_chat";

#define FILE_PATH "/spiffs/demo.pcm"  // SPIFFS 中文件的路径
#define chat_url "ws://192.168.173.126:8090/v1/message/chat?app_id=&api_key=&api_secret="
#define stt_url "ws://192.168.173.126:8090/v1/message/chat?app_id=&api_key=&api_secret="
#define tts_url "ws://192.168.173.126:8090/v1/message/chat?app_id=&api_key=&api_secret="

void handle_tts_data(const char *data) {
    // Process data from TTS
    printf("Received TTS data: %s\n", data);
    // End of processing
}
void handle_chat_data(const char *data) {
    // Process data from chat response
    printf("Received chat response: %s\n", data);
    // Call next step
    websocket_app_start_tts(tts_url, data, handle_tts_data);
}

// Define callback functions for each stage
void handle_stt_data(const char *data) {
    // Process data from STT
    printf("Received STT data: %s\n", data);
    // Call next step
    websocket_app_start_chat(chat_url, data, handle_chat_data);
}


void app_main(void)
{

    ESP_ERROR_CHECK(nvs_flash_init());

    char *chat_message = "你是谁";
    char *tts_message = "我是星火大模型机器人";
    wifi_init_sta();
    bsp_spiffs_mount();
    websocket_app_start_init();

    websocket_app_start_stt(stt_url,FILE_PATH,handle_stt_data);
    // websocket_app_start_chat(chat_url,chat_message,handle_chat_data);
    // websocket_app_start_tts(tts_url,tts_message,handle_tts_data);
    // test_http_client();


 
}
